package com.qianya.system.manage.web.sys.controller;

import com.qianya.system.manage.web.sys.model.SysParam;
import com.qianya.system.manage.web.sys.service.ISysParamService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;

import org.springframework.web.bind.annotation.*;
import org.springframework.beans.BeanUtils;
import com.qianya.model.common.CommonResult;
import com.qianya.model.pojo.sys.qo.SysParamQO;

import javax.servlet.http.HttpServletRequest;
    import org.springframework.web.bind.annotation.RestController;
/**
* <p>
    * 字典 前端控制器
    * </p>
*
* @author lhl
* @since 2020-06-12
*/
    @RestController
@RequestMapping("/sys/sys-param")
@Api(value = "SysParamController", tags = "字典接口")
@Slf4j
public class SysParamController {


    @Autowired
    private ISysParamService sysParamService;

    @PutMapping(value = "/update")
    @ApiOperation("修改字典")
    public CommonResult update(@RequestBody  SysParamQO sysParamQO,HttpServletRequest request){
        SysParam sysParam = new SysParam();
        BeanUtils.copyProperties(sysParamQO,sysParam);
        return sysParamService.renewal(sysParam,request);
    }
    @PutMapping(value = "/updateCache")
    @ApiOperation("redis缓存手动更新")
    public CommonResult updateCache(){
        sysParamService.paramCache();
        return CommonResult.success();
    }
    @PostMapping(value = "/save")
    @ApiOperation("添加字典")
    public CommonResult save(@RequestBody  SysParamQO sysParamQO,HttpServletRequest request){
        SysParam sysParam = new SysParam();
        BeanUtils.copyProperties(sysParamQO,sysParam);
        return sysParamService.create(sysParam,request);
    }

    @ApiOperation("查找字典")
    @GetMapping(value = "/find")
    public CommonResult find(@RequestBody SysParamQO sysParamQO,HttpServletRequest request){

        return sysParamService.find(sysParamQO);
    }

    }
